#include "Regex.h"

namespace etel{
	Regex::Regex(RegexType regexType) :_regexType(regexType){}

	//RString
	RString::~RString(){
		if (_isDyString) delete [] _string;
	}
	RString::RString(CodeType string, bool isDyString)
		:Regex(RegexType::String)
		, _string(string)
		, _isDyString(isDyString)
	{}
	EXTRACT(RString::extract){
		return false;
	}
	DUMP(RString::dump){
		swprintf_s(dump, EXP_SIZE, L"%c%s%c", STRING_DELI, _string, STRING_DELI);
		//wcscpy_s(dump,dumpSize,_string);
	}

	//RAnyChar
	RAnyChar::~RAnyChar(){}
	RAnyChar::RAnyChar()
		:Regex(RegexType::Dynamic)
	{}
	EXTRACT(RAnyChar::extract){
		return false;
	}
	DUMP(RAnyChar::dump){
		swprintf_s(dump, 2, L"%c", INF_CHAR);
	}

	//RCharRange
	RCharRange::~RCharRange(){}
	RCharRange::RCharRange(CodeUnitType leftChar, CodeUnitType rightChar)
		:Regex(RegexType::CharRange)
		, _leftChar(leftChar)
		, _rightChar(rightChar)
	{}
	EXTRACT(RCharRange::extract){
		return false;
	}
	DUMP(RCharRange::dump){
		swprintf_s(dump, 2, L"%c", RANGE_L);
		if (_leftChar != NULL){
			swprintf_s(++dump, 4, L"%c%c%c", STRING_DELI, _leftChar, STRING_DELI);
			swprintf_s(dump += 3, 2, L"%c", RANGE_I);
		}
		else swprintf_s(++dump, 2, L"%c", RANGE_I);
		if (_rightChar != NULL){
			swprintf_s(++dump, 4, L"%c%c%c", STRING_DELI, _rightChar, STRING_DELI);
			swprintf_s(dump+=3,2,L"%c",RANGE_R);
		}
		else swprintf_s(++dump, 2, L"%c", RANGE_R);
		//swprintf_s(dump, EXP_SIZE, L"%c%c%c%c%c%c%c%c%c", RANGE_L, STRING_DELI, _leftChar, STRING_DELI, RANGE_I, STRING_DELI, _rightChar, STRING_DELI, RANGE_R);	//[`a`-`b`]
	}

	//RReference
	RReference::~RReference(){
		if (_isDyRegexName) delete [] _regexName;
	}
	RReference::RReference(CodeType regexName, bool isDyRegexName, BasicSpace* basicSpace)
		:Regex(RegexType::Reference)
		, _regexName(regexName)
		, _isDyRegexName(isDyRegexName)
		, _basicSpace(basicSpace)
	{}
	EXTRACT(RReference::extract){
		return false;
	}
	DUMP(RReference::dump){
		wcscpy_s(dump, EXP_SIZE, _regexName);
	}
}